package liantiaoxifen.server;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Dao {
    private Connection connection;

    public Dao(Connection connection) {
        this.connection = connection;
    }

    public ResultSet selectDB(String sqlyj,String userName,String passWord){
        String sql=sqlyj;
        PreparedStatement ps= null;
        ResultSet r = null;
        try {
            ps = connection.prepareStatement(sql);
            ps.setString(1,userName);
            ps.setString(2,passWord);
            r = ps.executeQuery();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return r;
    }

    public ResultSet registerDB(String userName){
        String sql1="select username from user where username=?";
        try {
            PreparedStatement ps1=connection.prepareStatement(sql1);
            ps1.setString(1,userName);
            //查询用户名是否重复
            ResultSet r=ps1.executeQuery();
            return r;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
